<?php /* PROJECTS $Id: vw_idx_active.php,v 1.28.6.3 2006/11/19 16:01:34 gregorerhardt Exp $ */
global $projects;
global $AppUI, $company_id, $priority;

$perms =& $AppUI->acl();
$df = $AppUI->getPref('SHDATEFORMAT');
?>

<table id="idProjectList" width="100%" border="0" cellpadding="3" cellspacing="0" class="list">
<tr class="clickable">
	<th width="50px" nowrap="nowrap" id="project_color_identifier" onclick="setMode(this)">
		<?=$AppUI->_('Completed')?>
	</th>
	<th nowrap="nowrap" id="project_name" onclick="setMode(this)">
		<?=$AppUI->_('Reference Name')?>
	</th>
	<th nowrap="nowrap" id="company_name" onclick="setMode(this)">
		<?=$AppUI->_('Customer')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_start_date" onclick="setMode(this)">
		<?=$AppUI->_('Start')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Due Date')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_actual_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Amount')?>
	</th>
	<th width="16px" nowrap="nowrap" id="task_log_problem" onclick="setMode(this)">
		<?=$AppUI->_('Shipping type')?>
	</th>
	<th width="32px" nowrap="nowrap" id="user_username" onclick="setMode(this)">
		<?=$AppUI->_('Shipper')?>
	</th>
	<th width="70px" nowrap="nowrap" id="total_tasks" onclick="setMode(this)" class="last">
		<?=$AppUI->_('Tasks')?>
		<a href="?m=projects&orderby=my_tasks">(<?=$AppUI->_('My')?>)</a>
	</th>
</tr>

<?php
$none = true;
$first = true;
foreach ($projects as $row) {
	if (! $perms->checkModuleItem('projects', 'view', $row['project_id']))
		continue;
	// We dont check the percent_completed == 100 because some projects
	// were being categorized as completed because not all the tasks
	// have been created (for new projects)
	if ($row["project_status"] == 3) {
		$none = false;
		$start_date = intval( @$row["project_start_date"] ) ? new CDate( $row["project_start_date"] ) : null;
		$end_date = intval( @$row["project_end_date"] ) ? new CDate( $row["project_end_date"] ) : null;
		$actual_end_date = intval( @$row["project_actual_end_date"] ) ? new CDate( $row["project_actual_end_date"] ) : null;
		$style = (( $actual_end_date > $end_date) && !empty($end_date)) ? 'style="color:red; font-weight:bold"' : '';

		$s = $first ? '<tr class="first">' : '<tr class="second">'; $first = !$first;
		$s .= '<td align="center" style="background-color:#'
			. $row["project_color_identifier"] . '">';
		$s .= '<font color="' . bestColor( $row["project_color_identifier"] ) . '">'
			. sprintf( "%.1f%%", $row["project_percent_complete"] )
			. '</font>';
		$s .= '</td>';
		$s .= '<td class="clickable" onclick="viewProject('.$row["project_id"].')">';
		$s .= htmlspecialchars( $row["project_name"], ENT_QUOTES );
		$s .= '</td>';
		if ($perms->checkModuleItem('companies', 'access', $row['project_company'])) {
			$s .= '<td class="clickable" onclick="Company('.$row['project_company'].').show()" title="' . htmlspecialchars( $row["company_description"], ENT_QUOTES ) . '">' . htmlspecialchars( $row["company_name"], ENT_QUOTES ) . '</td>';
		} else {
			$s .= '<td>'.htmlspecialchars( $row["company_name"], ENT_QUOTES ).'</td>';
		}

		$s .= '<td align="center">'. ($start_date ? $start_date->format( $df ) : '-') .'</td>';
		$s .= '<td align="right" nowrap="nowrap" style="background-color:'.$priority[$row['project_priority']]['color'].'">';
		$s .= ($end_date ? $end_date->format( $df ) : '-');
		$s .= '</td>';
		$s .= '<td align="right">';
//		$s .= $actual_end_date ? '<a href="?m=tasks&a=view&task_id='.$row["critical_task"].'">' : '';
//		$s .= $actual_end_date ? '<span '. $style.'>'.$actual_end_date->format( $df ).'</span>' : '-';
//		$s .= $actual_end_date ? '</a>' : '';
		$s .= '0.00';
		$s .= '</td>';
		$s .= '<td align="left" nowrap="nowrap">';
		//$s .= $row["task_log_problem"] ? '<a href="?m=tasks&a=index&f=all&project_id='.$row["project_id"].'">' : '';
		//$s .= $row["task_log_problem"] ? dPshowImage( './images/problem.gif', 12, 12, 'Problem', 'Problem' ): '-';
		//$s .= $row["task_log_problem"] ? '</a>' : '';
		$s .= $row['project_shipping_type_name'];
		$s .= '</td>';
		$s .= '<td nowrap="nowrap">' . htmlspecialchars( $row["user_username"], ENT_QUOTES ) . '</td>';
		$s .= '<td align="center" nowrap="nowrap">';
		$s .= $row["total_tasks"] . ($row["my_tasks"] ? ' ('.$row["my_tasks"].')' : '');
		$s .= '</td>';
		$s .= '</tr>';
		echo $s;
	}
}

if ($none) {
	echo '<tr><td colspan="100%">' . $AppUI->_( 'No projects available' ) . '</td></tr>';
}
?>
</table>
<script>
Table("idProjectList").setNormalHover(1);
</script>
